﻿using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Games;

namespace Jinhua
{
    /// <summary>
    /// 比较两幅手牌的大小
    /// </summary>
    public class DeckOfCardComparer : IComparer<DeckOfCard>
    {
        /// <summary>
        /// 比较两幅手牌的大小
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public int Compare([AllowNull] DeckOfCard x, [AllowNull] DeckOfCard y)
        {
            var result = x.KindOfCards - y.KindOfCards;
            if (result == 0)
            {
                //牌型相同则挨个判断
                for (int index = x.Count - 1; index >= 0; index--)
                {
                    result = x[index].Suit - y[index].Suit;
                    if (result != 0)
                    {
                        break;
                    }
                }
            }

            return result;
        }
    }
}
